

<h3>Saved Filters</h3>
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Owner</th>
      <th>Type</th>
      <th>Public</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <% @saved_filters.each do |filter| %>
      <tr>
        <td><%= filter.name %></td>
        <% if filter.user_id.present? %>
          <td><%= User.where(id: filter.user_id).first.try(:[], "email") %></td>
        <% else %>
          <td>Unknown</td>
        <% end %>
        <td><%= filter.saved_filter_type %></td>
        <td><%= filter.public %></td>
        <td>
          <%= link_to "Show Results", send("search_#{filter.saved_filter_type.pluralize.downcase}_path", :saved_filter_id=>filter.id), class: "button tiny" %>
          <%= link_to "Edit", edit_saved_filter_path(filter), class: "button tiny" %>
          <%= link_to 'Destroy', filter, method: :delete, data: { confirm: 'Are you sure?' }, class: "button tiny alert" %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Owner</th>
      <th>Type</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <h3>Public Filters

      <h3>
        <% @added_public_saved_filters.each do |filter| %>
          <tr>
            <td><%= filter.name %></td>
            <% if filter.user_id.present? %>
              <td><%= User.where(id: filter.user_id).first.try(:[], "email") %></td>
            <% else %>
              <td>Unknown</td>
            <% end %>
            <td><%= filter.saved_filter_type %></td>
            <td>
              <%= link_to "Show Results", send("search_#{filter.saved_filter_type.pluralize.downcase}_path", :saved_filter_id=>filter.id), class: "button tiny" %>
              <%= link_to "Remove", remove_saved_filter_path(id: filter.id, :saved_filter_type=>params[:saved_filter_type]),:method=>:post, class: "button tiny" %>
            </td>
          </tr>
        <% end %>
        <% @public_saved_filters.each do |filter| %>
          <tr>
            <td><%= filter.name %></td>
            <% if filter.user_id.present? %>
              <td><%= User.where(id: filter.user_id).first.try(:[], "email") %></td>
            <% else %>
              <td>Unknown</td>
            <% end %>
            <td><%= filter.saved_filter_type %></td>
            <td>
              <%= link_to "Show Results", send("search_#{filter.saved_filter_type.pluralize.downcase}_path",:saved_filter_id=>filter.id), class: "button tiny" %>
              <%= link_to "Add", add_saved_filter_path(id: filter.id, :saved_filter_type=>params[:saved_filter_type]), :method=>:post, class: "button tiny" %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
